package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import fl.text.TLFTextField;
	
	import flash.display.*;
	import flash.display.InteractiveObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.*;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.engine.ElementFormat;
	import flash.ui.*;
	import flash.ui.Keyboard;
	import flash.utils.*;
	import flash.utils.getDefinitionByName;
	
	import flashx.textLayout.edit.EditManager;
	import flashx.textLayout.edit.SelectionManager;
	import flashx.textLayout.edit.SelectionState;
	import flashx.textLayout.elements.FlowElement;
	import flashx.textLayout.elements.ParagraphElement;
	import flashx.textLayout.elements.SpanElement;
	import flashx.textLayout.elements.TextFlow;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.plaf.*;
	import org.aswing.skinbuilder.SkinProgressBarBackground;
	import org.aswing.skinbuilder.SkinProgressBarForeground;
	import org.aswing.skinbuilder.SkinScrollBarBackground;
	import org.aswing.skinbuilder.SkinScrollBarThumb;
	import org.aswing.skinbuilder.SkinScrollBarUI;
	
	public class FrameInfoMain  extends JFrame
	{
		//members define
		private var scrollpane:JScrollPane;
		private var _textArea:MultilineLabel;
		public function FrameInfoMain()
		{
			super();
			setDragable(false);
			setClosable(false);
			setResizable(false);
			setTitleBar(null);
			setBorder(new EmptyBorder());
			this.setBackgroundDecorator(new SolidBackground(new ASColor(0,0)));
			
			//component creation
			setSize(new IntDimension(190, 100));
			setPreferredSize(new IntDimension(190, 100));
			var layout0:BoxLayout = new BoxLayout();
			getContentPane().setLayout(layout0);
			
			scrollpane = new JScrollPane();
			scrollpane.setLocation(new IntPoint(5, 5));
			
			_textArea = new MultilineLabel();
			_textArea.setSize(new IntDimension(200, 120));
			
			//component layoution
			getContentPane().append(scrollpane);
			
			scrollpane.append(_textArea);
			
			//--------------
			scrollpane.getVerticalScrollBar().setVisible(true);
			scrollpane.setVerticalScrollBarPolicy(JScrollPane.SCROLLBAR_NEVER);
			scrollpane.setHorizontalScrollBarPolicy(JScrollPane.SCROLLBAR_NEVER);
			setImages();
			this.setEnabled(false);
			getContentPane().setEnabled(false);
			scrollpane.setEnabled(false);
			this.setClipMasked(false);
			getContentPane().setClipMasked(false);
			//_textArea.setEnabled(false);
		}
		
		//private var _scrollPane:JScrollPane = null
		public function setImages():void
		{
			//setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_chat_bg") as DisplayObject));
			//this.setBackground(new ASColor(0xeeeeee,0.8));
			//setBackgroundDecorator(new SolidBackground(new ASColor(0x111111,0.8)));
			setBackgroundDecorator(null);
			scrollpane.getVerticalScrollBar().setUIElement(true);
			scrollpane.getVerticalScrollBar().setUI(new MyScrollBarUI);
			
			_textArea.setFont(new ASFont("宋体", 12, false, false, false, false));
			_textArea.setForeground(ASColor.ORANGE);
			_textArea.setEditable(false);
			//_textArea.setForeground(new ASColor(0xffffff, 1));
			_textArea.setWordWrap(true);
			_textArea.setBorder( new EmptyBorder);
			_textArea.setBackgroundDecorator(null);
			
			var filter:GlowFilter = new GlowFilter(0x000000, 1, 2, 2, 5);
			_textArea.filters = new Array(filter);
			_textArea.addEventListener(MouseEvent.CLICK, onClick);
			//getContentPane().addEventListener(MouseEvent.ROLL_OVER, onRollOver);
			//getContentPane().addEventListener(MouseEvent.ROLL_OUT, onRollOut);
			
			_textArea.addEventListener(TextEvent.LINK, linkHandler);
			
			//_textArea.setEnabled(false);
		}
		
		//private var _filterArray:Array = new Array(new GlowFilter(0xffff00, 1, 20, 20));
		private var background:AssetBackground = null;//new SolidBackground(new ASColor(0x033332,0.8));
		private function onRollOver(event:MouseEvent):void
		{
			//event.target.filters = _filterArray;
			//setBackgroundDecorator(background);
			if(background == null)
			{
				var square:Sprite = new Sprite();
				square.graphics.beginFill(0x033332, 0.8);
				square.graphics.drawRoundRectComplex(0,0,width,height,5,5,5,5);
				square.graphics.endFill();
				background = new AssetBackground(square as DisplayObject);
			}
			setBackgroundDecorator(background);
			//scrollpane.getVerticalScrollBar().setVisible(true);
			//scrollpane.setVerticalScrollBarPolicy(JScrollPane.SCROLLBAR_ALWAYS);
			this.paintImmediately();
			//scrollbar.setVisible(true);
		}
		
		private function onRollOut(event:MouseEvent):void
		{

			setBackgroundDecorator(null);
			this.paintImmediately();

		}
		
		private function onClick(event:MouseEvent):void
		{
			SceneMain.getInstance().onClick(event);
		}
		
		private function linkHandler(linkEvent:TextEvent):void 
		{
			var dtemp:Array = (linkEvent.text as String).split(',');
			if(dtemp.length != 5)
			{
				return;
			}
			
			var obj:Object = new Object;
			obj.m_nCharId = int(dtemp[0]);
			obj.m_szCharName = dtemp[1];
			obj.m_nLevel = int(dtemp[2]);
			obj.m_nRace = int(dtemp[3]);
			obj.m_nGender = int(dtemp[4]);
			
			var point:IntPoint = AsWingUtils.getStageMousePosition();
			FrameClickChar._objDest = obj;
			FrameClickChar._destCharId = int(obj.m_nCharId);
			FrameClickChar.show(_frame,point.x-_frame.x,point.y-_frame.y);
		}
		
		private var text:String  = new String();
		public function update():void
		{
			var showType:int = 0;//all
			text = "";
			if(_messages.length > 512)
			{
				_messages.splice(0,_messages.length - 512);
			}
			for each(var obj:String in _messages)
			{
				text += obj+"<br>";
			}
			_textArea.setHtmlText(text);
			_textArea.scrollToBottomLeft();
		}
		public static var _messages:Array = [];
		public static function showInfoTimeLimit(info:String):void
		{
			_messages.push(info);
			if(FrameInfoMain.isShowing())
				_frame.update();
		}
		private static var _frame:FrameInfoMain = null;
		public static function show():void
		{
			if(_frame == null)
			{
				_frame = new FrameInfoMain;
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);
			_frame.x = 1000+5;
			//_frame.y = 423;
			_frame.y = (Engine.H - _frame.height - 69);
			_frame.update();
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
	}
}